$(function(){
	
		$('#dep_result').datagrid({
		    url: "dep_dep_list.action",
		    iconCls: "icon-edit",
		    title: "部门列表",
		    striped: true,//条纹
		    fitColumns: true,//自动调整单元格宽度
		    rownumbers: false,//显示行号
		    singleSelect: true,//单选
		    pagination: false,//分页
		    toolbar: '#usli_dep',
		    columns: [[
		        {field: 'id', title: 'ID', width: 20},
		        {field: 'num', title: '顺序', width: 20},
		        {field: 'department', title: '部门名', width: 20},
		    ]]
		});
		
		
		//新建框
		$('#dep_add_dd').dialog({
			buttons:[{
				text:'添加',
				iconCls:'icon-ok',
				handler:function(){
					if(if_ip){
						$.post("dep_dep_add.action", $("#dep_add_form").serialize(), function(data) {
							if(data.status == "0") {
								alert(data.mess);
								$('#dep_add_dd').dialog('close');
								$('#dep_result').datagrid('reload');
							} else {
								alert(data.mess);
							}
						});
					}else{
						alert('无权限');	
					}	
				}
			},{
				text:'&nbsp;取消&nbsp;',
				handler:function(){
					$('#dep_add_dd').dialog('close');
				}
			}]
		});
		
		
		//修改框
		$('#dep_update_dd').dialog({
			buttons:[{
				text:'修改',
				iconCls:'icon-ok',
				handler:function(){
					if(if_ip){
						$.post("dep_dep_update.action", $("#dep_update_form").serialize(), function(data) {
							if(data.status == "0") {
								$('#dep_update_dd').dialog('close');
								alert(data.mess);
								$('#dep_result').datagrid('reload');
							} else {
								alert(data.mess);
							}
						});
					}else{
						alert('无权限');	
					}	
				}
			},{
				text:'&nbsp;取消&nbsp;',
				handler:function(){
					$('#dep_update_dd').dialog('close');
				}
			}]
		});
		
		
		$('#dep_del_dd').dialog({
			buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					$.messager.confirm('Confirm','删除部门，请慎重使用?',function(r){ 
						if(if_ip){
							var row = $('#dep_result').datagrid('getSelected');
							$.post("dep_dep_del.action", $("#dep_del_form").serialize(), function(data) {
								if(data.status == "0") {
									$('#dep_del_dd').dialog('close');
									alert(data.mess);
									$('#dep_result').datagrid('reload');
								} else {
									alert(data.mess);
								}
							});
						}else{
							alert('无权限');	
						}
						$("#pwd").attr("value","");
					});  
				}
			},{
				text:'&nbsp;取消&nbsp;',
				handler:function(){
					$('#dep_del_dd').dialog('close');
					$("#pwd").attr("value","");
				}
			}]
		});
	
});	

function dep_add_dd() {
	$('#dep_add_dd').dialog('open').dialog('setTitle','添加部门');
}

function dep_del_dd() {
	var row = $('#dep_result').datagrid('getSelected');
	$("#d_id").val(row.id);
	$('#dep_del_dd').dialog('open').dialog('setTitle','删除部门');
}

function dep_update_dd() {
	var row = $('#dep_result').datagrid('getSelected');
	$("#u_id").val(row.id);
	$("#num").val(row.num);
	$("#department").val(row.department);
	$('#dep_update_dd').dialog('open').dialog('setTitle','修改部门');
}





